﻿using System;
using System.Configuration;
using System.Reflection;
using Castle.ActiveRecord.Framework;
using WebConversion.Common.UrlRewriter;
using WebConversion.Common.WebCache;

namespace WebConversion.Common.Configuration
{
    public class AppConfigReader
    {
        #region Environment

        public static string AppRootPath = AppDomain.CurrentDomain.BaseDirectory;
        public static string ConfigurationRootPath = AppRootPath + "Configuration\\";

        #endregion

        #region Rewriter Rule
        public static RewriterRuleConfiguration GetRewriterRules()
        {
            const string configurationSectionName = "RewriterRuleConfiguration";
            return (RewriterRuleConfiguration)ConfigurationManager.GetSection(configurationSectionName);
        }
        #endregion

        #region Active Record
        public static IConfigurationSource GetActiveRecordConfig()
        {
            const string configurationSectionName = "activerecord";
            return (IConfigurationSource)ConfigurationManager.GetSection(configurationSectionName);
        }


        public static Assembly GetActiveRecordModuleAssembly()
        {
            const string webconversionModule = "WebConversion.Module";
            return Assembly.Load(webconversionModule);
        }
        #endregion

        #region Menu

        public static string GetMainMenu()
        {
            return CacheManager.Instance.Get<string>("MainMenu", StaticDataProvider.GetMainMenu);
        }

        public static string GetSubMenu()
        {
            return CacheManager.Instance.Get<string>("SubMenu", StaticDataProvider.GetSubMenu);
        }

        #endregion
    }
}
